function disabled_forms(s)
{
	if (s==1 || s==0)
	{
		document.getElementById("send").disabled=s;


		document.getElementById("mail").disabled=s;
		document.getElementById("name").disabled=s;
		document.getElementById("sex0").disabled=s;
		document.getElementById("sex1").disabled=s;
		document.getElementById("bday").disabled=s;
		document.getElementById("bmonth").disabled=s;
		document.getElementById("byear").disabled=s;
		document.getElementById("phone").disabled=s;
		document.getElementById("im").disabled=s;
		document.getElementById("about").disabled=s;
		document.getElementById("interes").disabled=s;
		document.getElementById("citata").disabled=s;
		document.getElementById("filename").disabled=s;
		
		for (i=0;i<=11;i++)
		{
			document.getElementById("phone_global").getElementsByTagName("input")[i].disabled=s;
		}
		//document.getElementById("phone-add-button").disabled=s;
	}
	
}

function check_nic()
{
	var input = document.getElementById("nic");
	var div_message = document.getElementById("message");

	var znachenie = input.value;

	if(znachenie.length <= 3)
	{
		document.getElementById("pass1").disabled=1;
		document.getElementById("pass2").disabled=1;
		
		disabled_forms(1);
		
		div_message.innerHTML = '<span class="imp">Не меньше 4-х</span>';
		return false;
	}
	else
	{
		var req = getXmlHttp(); 
		req.open('GET', 'check_nic.pl?nic='+znachenie, true);
		req.onreadystatechange = function() 
		{
			if (req.readyState == 4) 
			{
				if(req.status == 200)
				{
					if(znachenie != '')
					{
						if (req.responseText != '1')
						{
							div_message.innerHTML = '<span class="imp">' + req.responseText + '</span>';
							
							disabled_forms(1);
							
							document.getElementById("pass1").disabled=1;
							document.getElementById("pass2").disabled=1;
							
							return false;
							//задисейбить формы
						}
						else 
						{
							div_message.innerHTML = '<span style="color: green">Имя свободно</span>';
							
							disabled_forms(0);
							document.getElementById("pass1").disabled=0;
							document.getElementById("pass2").disabled=0;
						}//не задисэйбливать формы
					}
					else div_message.innerHTML = '&nbsp;';
				}
			}
		}
		req.send(null)
		return true;
	}
}

function phone_add(s)
{
	var div_phone = document.getElementById("phone_"+s);
	//alert(div_phone.style.display);
	if(div_phone.style.display == "none")
	{
		div_phone.style.display = "block";
	}
	else
	{
		div_phone.style.display = "none";
	}
}

function phone_arr() //Функция записи готового массива в textarea для ожидания передачи!
{
	var phone;
	if(document.getElementById("phone_mob").style.display == "block")
	{
	
		var phone_country_mob = document.getElementsByName("phone_country_mob")[0].value;
		var phone_city_mob = document.getElementsByName("phone_city_mob")[0].value;
		var phone_number_mob = document.getElementsByName("phone_number_mob")[0].value;
	
		phone = 'phone_mob:' + phone_country_mob + ' ' + phone_city_mob + ' ' + phone_number_mob;
		var phone_mob = 'phone_mob:' + phone_country_mob + ' ' + phone_city_mob + ' ' + phone_number_mob; 
		if(phone_mob.match(/^phone_mob:[0-9]{1,3} [0-9]{1,5} [0-9]{1,7}/))
		{
				//alert('phone_mob_true');
		}
		else
		{
			alert('Неправельный мобильный телефон');
			return;
		}
		
	}
	else
	{
		phone = 'phone_mob:';
	}

	if(document.getElementById("phone_home").style.display == "block")
	{
		var phone_country_home = document.getElementsByName("phone_country_home")[0].value;
		var phone_city_home = document.getElementsByName("phone_city_home")[0].value;
		var phone_number_home = document.getElementsByName("phone_number_home")[0].value;
	
		if(phone != '')
		{
			var phone = phone + ",";
		}
		phone = phone + 'phone_home:' + phone_country_home + ' ' + phone_city_home + ' ' + phone_number_home;
		var phone_home = 'phone_home:' + phone_country_home + ' ' + phone_city_home + ' ' + phone_number_home;
		if(phone_home.match(/^phone_home:[0-9]{1,3} [0-9]{1,5} [0-9]{1,7}/))
		{
				//alert('phone_home_true');
		}
		else
		{
			alert('Неправельный городской телефон');
			return;
		}
		
	}
	else
	{
		if(phone != '')
		{
			var phone = phone + ",";
		}
		phone = phone + 'phone_home:';
	}
	if(document.getElementById("phone_work").style.display == "block")
	{
		var phone_country_work = document.getElementsByName("phone_country_work")[0].value;
		var phone_city_work = document.getElementsByName("phone_city_work")[0].value;
		var phone_number_work = document.getElementsByName("phone_number_work")[0].value;
		
		if(phone != '')
		{
			var phone = phone + ",";
		}
		phone = phone + 'phone_work:' + phone_country_work + ' ' + phone_city_work + ' ' + phone_number_work;
		var phone_work = 'phone_work:' + phone_country_work + ' ' + phone_city_work + ' ' + phone_number_work;
		if(phone_work.match(/^phone_work:[0-9]{1,3} [0-9]{1,5} [0-9]{1,7}/))
		{
				//alert('phone_work_true');
		}
		else
		{
			alert('Неправельный рабочий телефон');
			return;
		}
	}
	else
	{
		if(phone != '')
		{
			var phone = phone + ",";
		}
		phone = phone + 'phone_work:';
	}
	if(document.getElementById("phone_other").style.display == "block")
	{
		var phone_country_other = document.getElementsByName("phone_country_other")[0].value;
		var phone_city_other = document.getElementsByName("phone_city_other")[0].value;
		var phone_number_other = document.getElementsByName("phone_number_other")[0].value;
		
		if(phone != '')
		{
			var phone = phone + ",";
		}
		phone = phone + 'phone_other:' + phone_country_other + ' ' + phone_city_other + ' ' + phone_number_other;
		var phone_other = 'phone_other:' + phone_country_other + ' ' + phone_city_other + ' ' + phone_number_other;
		if(phone_other.match(/^phone_other:[0-9]{1,3} [0-9]{1,5} [0-9]{1,7}/))
		{
				//alert('phone_other_true');
		}
		else
		{
			alert('Неправельный альтернативный телефон');
			return;
		}
	}
	else
	{
		if(phone != '')
		{
			var phone = phone + ",";
		}
		phone = phone + 'phone_other:';
	}
	if(!phone)
	{
		phone = '';
	}
	document.getElementsByName("phone")[0].value = phone;
	return true;
}

function check_pass_value()//сравниваем пароли
{
	var message_pass = document.getElementById("message_pass");
	
	var PASS1 = document.getElementById("pass1").value;
	var PASS2=document.getElementById("pass2").value;
	
	if (PASS1 == '')
	{
		message_pass.innerHTML = '<span style="color: red">Незаполнены</span>';
		document.getElementById("nic").disabled=1;
		disabled_forms(1)
		return false;
	}
	
	if(PASS1==PASS2)
	{
		message_pass.innerHTML = '<span style="color: green">Совпадают</span>';
		
		document.getElementById("nic").disabled=0;
		disabled_forms(0)
		return true;
	}
	else
	{
		message_pass.innerHTML = '<span style="color: red">Не совпадают</span>';
		
		document.getElementById("nic").disabled=1;
		disabled_forms(1)
		return false;
	}
}

function mailvalid()
{
	var mail = document.getElementById("mail").value;
	var message_email = document.getElementById("message_email");
	if(!mail)
	{
		message_email.innerHTML = '<span style="color: red">Не заполненно</span>';
		return false;
	}
	if(mail.match(/^[A-Za-z0-9._]{1,32}@[A-Za-z0-9._]{1,32}.[a-zA-Z]{2,6}$/))
	{
		message_email.innerHTML = '<span style="color: green">Верно</span>';
		return true;
	}
	else
	{
		message_email.innerHTML = '<span style="color: red">Неверный e-mail</span>';
		return false;
	}
}

function sexvalid()
{
	//alert(document.getElementsByName("sex").value);
	var message_sex = document.getElementById("message_sex");
	
	var sexm = document.getElementById("sex1").checked;	
	var sexw = document.getElementById("sex0").checked;
	if (sexm || sexw)
	{
		message_sex.innerHTML = '<span style="color: green">Отлично</span>';
		return true;
	}
	else
	{
		message_sex.innerHTML = '<span style="color: red">Не выбранно</span>';
		return false;
	}
	
}

//				function phonevalid()
//				{
//					var phone_country_mob = document.getElementsByName("phone_country_mob")[0].value;
//					var phone_city_mob = document.getElementsByName("phone_city_mob")[0].value;
//					var phone_number_mob = document.getElementsByName("phone_number_mob")[0].value;
//					
//					phone = 'phone_mob:' + phone_country_mob + ' ' + phone_city_mob + ' ' + phone_number_mob;
//					
//					//if(phone_number_mob.match(/^[0-9]{1,7}\$/)) return true;
//					//alert(phone);
//					if(phone.match(/^phone_mob:[0-9]{1,3}\\ [0-9]{1,5}\\ [0-9]{1,7}\$/)) return true;
//					alert('Неправельный phone_mob');
//					return false;
//				}

function check()
{
//					phone_arr();
	var phone_exit = document.getElementsByName("phone")[0].value;
	//alert(phone_exit);
	if((phone_arr()) && (mailvalid()) && (check_pass_value()) && (check_nic()) && (sexvalid()))
	{
			document.forms.register.submit();
			reload_captcha();
			//alert("все правельно");
	}
	else
	{
			alert("При заполнение допушены ошибки");
	}
	//alert(document.getElementsByName(filename).value);
	//phonevalid();
}

function startUpload()
{
	document.getElementById('f1_upload_process').style.visibility = 'visible';
	return true;
}

function stopUpload(success)
{
  var result = '';
  if (success == 1){
	 document.getElementById('result').innerHTML =
	   '<span class="msg">Регистрация была произведена уснешно<\/span><br/><br/>';
  }
  else {
	 document.getElementById('result').innerHTML = 
	   '<span class="imp">При регистрации возникли ошибки<\/span><br/><br/>';
  }
  document.getElementById('f1_upload_process').style.visibility = 'hidden';
  return true;   
}
